Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

30431 implement format for history with docs #30962

Merged

Conversation

TheHipbot
Copy link
Contributor

- What I did
Adds the --format option to the history command. Part of #30431

- How I did it
Refactored history to use a formatter, add the format flag

- How to verify it
Wrote unit tests to check that formatter is working correctly.

- Description for the changelog

Adds --format option to history command

- A picture of a cute animal (not mandatory but encouraged)

trunc bool
h image.HistoryResponseItem
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add MarshalJSON so that {{json .}} works

call func() string
}

func TestHistoryContext_ID(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The granularity of the added tests seems different from existing tests.
(Please refer to existing *_test.go)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test against the full table view, but I'm not sure if this is what you meant.

@vdemeester vdemeester added status/1-design-review status/failing-ci Indicates that the PR in its current state fails the test suite and removed status/0-triage labels Feb 13, 2017
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design LGTM 🐮

@TheHipbot
Copy link
Contributor Author

Sorry, I was having trouble running the integration tests, I'll fix this up tonight and update the PR.

@TheHipbot TheHipbot force-pushed the 30431-implement-format-for-history-with-docs branch 3 times, most recently from fb537b9 to 6b40c3c Compare February 14, 2017 04:48
@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Feb 14, 2017
@TheHipbot TheHipbot force-pushed the 30431-implement-format-for-history-with-docs branch from 2438070 to 9523ac5 Compare February 14, 2017 15:26
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Feb 14, 2017
@TheHipbot
Copy link
Contributor Author

Is this still failing CI?

@cpuguy83 cpuguy83 added status/2-code-review and removed status/1-design-review status/failing-ci Indicates that the PR in its current state fails the test suite labels Feb 17, 2017
@AkihiroSuda
Copy link
Member

I confirmed it works, so code LGTM

  • Please squash commits
  • Probably we don't need an integration test

@TheHipbot TheHipbot force-pushed the 30431-implement-format-for-history-with-docs branch from 39ea636 to 3be6e78 Compare February 21, 2017 01:58
@TheHipbot
Copy link
Contributor Author

Squashed and removed the integration test.

@AkihiroSuda
Copy link
Member

@yongtang PTAL?

| Placeholder | Description|
| ---- | ---- |
| `.ID` | Image ID |
| `.CreatedSince` | Elapsed time since the image was created |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems both Created and CreatedSince has been defined for placeholders. Though here the Created is not mentioned in the docs.

I am wondering if we add both in the docs, or, maybe we could just merge Created and CreatedSince into one placeholder func?

@yongtang
Copy link
Member

yongtang commented Feb 21, 2017

@TheHipbot it looks like --human is only useful when --format "table" (or no --format is used):

ubuntu@ubuntu:~/docker$ docker history --format '{{.Created}}' --human=false busybox
2017-01-13T14:13:54-08:00
2017-01-13T14:13:53-08:00
ubuntu@ubuntu:~/docker$ docker history --format 'table {{.Created}}' --human=false busybox
CREATED AT
2017-01-13T14:13:54-08:00
2017-01-13T14:13:53-08:00
ubuntu@ubuntu:~/docker$ docker history --format 'table {{.Created}}' --human busybox
CREATED AT
2017-01-13T14:13:54-08:00
2017-01-13T14:13:53-08:00
ubuntu@ubuntu:~/docker$ docker history --format 'table' --human busybox
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
7968321274dc        5 weeks ago         /bin/sh -c #(nop)  CMD ["sh"]                   0B                  
<missing>           5 weeks ago         /bin/sh -c #(nop) ADD file:707e63805c0be1a...   1.11MB              
ubuntu@ubuntu:~/docker$ 

You may need to check the value of c.human inside Created() (and/or CreatedSince()) to render the output string in either human or non-human format accordingly. For example,

func (c *historyContext) Created() string {
	c.AddHeader(createdAtHeader)
        if c.human {
          .... 
        }
	return time.Unix(c.h.Created, 0).Format(time.RFC3339)
}

Also, I am wondering if it make sense to merge Created() and CreatedSince()?

@TheHipbot
Copy link
Contributor Author

@yongtang I was originally thinking to provide both options, which I should have added to the docs. That being said it also makes sense to combine so I will update the PR with the two combined as Created() and update the docs to reflect that

@TheHipbot TheHipbot force-pushed the 30431-implement-format-for-history-with-docs branch from 3be6e78 to 49c9964 Compare February 22, 2017 03:49
@TheHipbot TheHipbot force-pushed the 30431-implement-format-for-history-with-docs branch from 49c9964 to ad95a3b Compare March 4, 2017 18:11
@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Mar 6, 2017
@TheHipbot TheHipbot force-pushed the 30431-implement-format-for-history-with-docs branch from 39ff38d to 60cbecd Compare March 7, 2017 01:27
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Mar 7, 2017
@tonistiigi
Copy link
Member

@yongtang PTAL

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

| `.CreatedAt` | Timestamp of when image was created |
| `.CreatedBy` | Command that was used to create the image |
| `.Size` | Image disk size |
| `.Comment` | Comment for image |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the doc to align the table like below so that it is easy to update in the future?

| Placeholder     | Description |
| --------------- | ----------- |
| `.ID`           | Image ID    |
| `.CreatedSince` | Elapsed time since the image was created if --human=true, otherwise timestamp of when image was created |
| `.CreatedAt`    | Timestamp of when image was created |
| `.CreatedBy`    | Command that was used to create the image |
| `.Size`         | Image disk size |
| `.Comment`      | Comment for image |

var created string
created = units.HumanDuration(time.Now().UTC().Sub(time.Unix(int64(c.h.Created), 0)))
return created + " ago"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it seems that CreatedAt and CreatedSince is pretty much the same except for the ago. And --human flag does not have an impact to the rendering

I am wondering if CreatedAt should use time.Unix(int64(c.h.Created), 0).String() (just like docker images --format) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up having to separate these again due to some changes in how the headers are output with the formatters. I added to the docs to have both in the template.

…ormatter

Signed-off-by: Jeremy Chambers <jeremy@thehipbot.com>

Adds to history documentation for --format

Signed-off-by: Jeremy Chambers <jeremy@thehipbot.com>

Adds MarshalJSON to historyContext for {{json .}} format

Signed-off-by: Jeremy Chambers <jeremy@thehipbot.com>

Adds back the --human option to history command

Signed-off-by: Jeremy Chambers <jeremy@thehipbot.com>

Cleans up formatter around --human option for history, Adds integration test for --format option of history

Signed-off-by: Jeremy Chambers <jeremy@thehipbot.com>

Adds test for history formatter checking full table results, Runs go fmt on touched files

Signed-off-by: Jeremy Chambers <jeremy@thehipbot.com>

Fixes lint errors in formatter/history

Signed-off-by: Jeremy Chambers <jeremy@thehipbot.com>

Runs go fmt on cli/command/formatter/history.go

Signed-off-by: Jeremy Chambers <jeremy@thehipbot.com>

sRemoves integration test for --format option of history

Merges Created and CreatedSince in docker history formatter, Updates docs and tests
@TheHipbot TheHipbot force-pushed the 30431-implement-format-for-history-with-docs branch from 60cbecd to 6bc1f34 Compare March 11, 2017 20:04
@TheHipbot
Copy link
Contributor Author

Looks like Jenkins ran out of space on one of those builds

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐮
/cc @thaJeztah for docs review

@tonistiigi
Copy link
Member

ping @thaJeztah

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I agree with #30962 (comment), but it's just a nit so let's get this merged. I can do a quick follow up to address it

@thaJeztah thaJeztah merged commit a3ab463 into moby:master Apr 16, 2017
@thaJeztah thaJeztah added this to the 17.06 milestone Apr 16, 2017
dnephin pushed a commit to dnephin/docker that referenced this pull request Apr 17, 2017
…or-history-with-docs

30431 implement format for history with docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants